<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="iOS开发之C语言函数库"><meta name="keywords" content="iOS"><meta name="author" content="kyren"><meta name="copyright" content="kyren"><title>iOS开发之C语言函数库 | Kyren's Blog</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.9.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.9.0"><meta name="format-detection" content="telephone=no"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://hm.baidu.com"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cf87fcdbd9ab7cf93d894f7c219ae78f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();</script><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script src="https://v1.hitokoto.cn/?encode=js&amp;charset=utf-8&amp;select=.footer_custom_text" defer></script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  hexoVersion: '6.2.0'
} </script><meta name="generator" content="Hexo 6.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar" data-display="true"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://avatars.githubusercontent.com/u/5827823?v=4"></div><div class="author-info__name text-center">kyren</div><div class="author-info__description text-center">huluo的技术博客</div><div class="follow-button"><a target="_blank" rel="noopener" href="https://github.com/huluo666">Follow Me</a></div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">239</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">41</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">29</span></a></div><hr><div class="author-info-links"><div class="author-info-links__title text-center">Links</div><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:9090/">Jira</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:8090/">Confluence</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://bloc.leniugame.com/">Leniu</a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">Kyren's Blog</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus">   <a class="site-page" href="/">主页</a><a class="site-page" href="/essay">随笔</a><a class="site-page" href="/archives">归档</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a><a class="site-page" href="/about">关于</a></span><span class="pull-right"><a class="site-page social-icon search"><i class="fa fa-search"></i><span> 搜索</span></a></span></div><div id="post-info"><div id="post-title">iOS开发之C语言函数库</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2016-04-16</time></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><p>在iOS开发中不可避免的需要使用数学函数进行计算，我们可以使用C标准库头文件&lt;math.h&gt;中定义的数学常量宏及数学函数来进行基本的数学计算操作，这些C函数都可以在微软的<code>MSDN</code>API库中找到。(<a target="_blank" rel="noopener" href="https://msdn.microsoft.com/zh-cn/library">https://msdn.microsoft.com/zh-cn/library</a> )</p>
<p><strong>一、 iOS常用示例如：</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">//计算最大值、最小值、绝对值</span><br><span class="line">#define MAX(A,B) ((A) &gt; (B) ? (A) : (B))</span><br><span class="line">#define MIN(A,B) ((A) &lt; (B) ? (A) : (B))</span><br><span class="line">#define ABS(A) ((A) &lt; 0 ? (-(A)) : (A))</span><br><span class="line"></span><br><span class="line">//计算scrollView索引</span><br><span class="line">int index = ABS(scrollView.contentOffset.x) / scrollView.frame.size.width;</span><br></pre></td></tr></table></figure>

<p><img src="http://upload-images.jianshu.io/upload_images/328273-4e58afd530e75b1d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"></p>
<p>相关函数申明请查看头文件<code>math.h</code><br><strong>二、具体函数释义如下：</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br></pre></td><td class="code"><pre><span class="line">/************************************************************</span><br><span class="line"> *                                                          *</span><br><span class="line"> *                  Math Functions（数学函数）                *</span><br><span class="line"> *                                                          *</span><br><span class="line"> ***********************************************************/</span><br><span class="line"></span><br><span class="line">#pragma mark --- 三角函数  a前缀表示取反  asin反三角函数</span><br><span class="line">//TODO: 求反余弦值</span><br><span class="line">extern float acosf(float);</span><br><span class="line">extern double acos(double);</span><br><span class="line">extern long double acosl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求反正弦值</span><br><span class="line">extern float asinf(float);</span><br><span class="line">extern double asin(double);</span><br><span class="line">extern long double asinl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求反正切值</span><br><span class="line">extern float atanf(float);</span><br><span class="line">extern double atan(double);</span><br><span class="line">extern long double atanl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求坐标值的反正切值</span><br><span class="line">extern float atan2f(float, float);</span><br><span class="line">extern double atan2(double, double);</span><br><span class="line">extern long double atan2l(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求余弦值</span><br><span class="line">extern float cosf(float);</span><br><span class="line">extern double cos(double);</span><br><span class="line">extern long double cosl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求正弦值</span><br><span class="line">extern float sinf(float);</span><br><span class="line">extern double sin(double);</span><br><span class="line">extern long double sinl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求正切值</span><br><span class="line">extern float tanf(float);</span><br><span class="line">extern double tan(double);</span><br><span class="line">extern long double tanl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求反双曲余弦值</span><br><span class="line">extern float acoshf(float);</span><br><span class="line">extern double acosh(double);</span><br><span class="line">extern long double acoshl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求反双曲正弦值</span><br><span class="line">extern float asinhf(float);</span><br><span class="line">extern double asinh(double);</span><br><span class="line">extern long double asinhl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求反双曲正切值</span><br><span class="line">extern float atanhf(float);</span><br><span class="line">extern double atanh(double);</span><br><span class="line">extern long double atanhl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求双曲余弦值</span><br><span class="line">extern float coshf(float);</span><br><span class="line">extern double cosh(double);</span><br><span class="line">extern long double coshl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求双曲正弦值</span><br><span class="line">extern float sinhf(float);</span><br><span class="line">extern double sinh(double);</span><br><span class="line">extern long double sinhl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求双曲正切值</span><br><span class="line">extern float tanhf(float);</span><br><span class="line">extern double tanh(double);</span><br><span class="line">extern long double tanhl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求取自然数e的幂</span><br><span class="line">extern float expf(float);</span><br><span class="line">extern double exp(double);</span><br><span class="line">extern long double expl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算参数以 2 为底的指数</span><br><span class="line">extern float exp2f(float);</span><br><span class="line">extern double exp2(double);</span><br><span class="line">extern long double exp2l(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算基础 e 指数参数，但不包括 1</span><br><span class="line">extern float expm1f(float);</span><br><span class="line">extern double expm1(double);</span><br><span class="line">extern long double expm1l(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 以e为底的对数（log10f则为10为底、log2f：2为底 ）</span><br><span class="line">extern float logf(float);</span><br><span class="line">extern double log(double);</span><br><span class="line">extern long double logl(long double);</span><br><span class="line"></span><br><span class="line">extern float log10f(float);//以10为底的对数</span><br><span class="line">extern double log10(double);</span><br><span class="line">extern long double log10l(long double);</span><br><span class="line"></span><br><span class="line">extern float log2f(float);//以2为底的对数</span><br><span class="line">extern double log2(double);</span><br><span class="line">extern long double log2l(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算基础 e 对数 1 加上参数</span><br><span class="line">extern float log1pf(float);</span><br><span class="line">extern double log1p(double);</span><br><span class="line">extern long double log1pl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 提取 _X 指数，作为一个带符号整数值为浮点格式</span><br><span class="line">extern float logbf(float);</span><br><span class="line">extern double logb(double);</span><br><span class="line">extern long double logbl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 浮点数分解为整数和小数。返回 _X 的有符号的小数部分</span><br><span class="line">extern float modff(float, float *);</span><br><span class="line">extern double modf(double, double *);</span><br><span class="line">extern long double modfl(long double, long double *);</span><br><span class="line"></span><br><span class="line">//TODO: 计算从尾数和指数的一个实数</span><br><span class="line">extern float ldexpf(float, int);</span><br><span class="line">extern double ldexp(double, int);</span><br><span class="line">extern long double ldexpl(long double, int);</span><br><span class="line"></span><br><span class="line">//TODO: 浮点数分解尾数和二为底的指数</span><br><span class="line">extern float frexpf(float, int *);</span><br><span class="line">extern double frexp(double, int *);</span><br><span class="line">extern long double frexpl(long double, int *);</span><br><span class="line"></span><br><span class="line">//TODO: 提取_X 指数为无符号整型值</span><br><span class="line">extern int ilogbf(float);</span><br><span class="line">extern int ilogb(double);</span><br><span class="line">extern int ilogbl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 以 FLT_RADIX乘以_X到乘幂运算_Y</span><br><span class="line">extern float scalbnf(float, int);</span><br><span class="line">extern double scalbn(double, int);</span><br><span class="line">extern long double scalbnl(long double, int);</span><br><span class="line"></span><br><span class="line">//TODO: 将浮点数乘以 FLT_RADIX 的整数幂。</span><br><span class="line">extern float scalblnf(float, long int);</span><br><span class="line">extern double scalbln(double, long int);</span><br><span class="line">extern long double scalblnl(long double, long int);</span><br><span class="line"></span><br><span class="line">//TODO: 浮点数绝对值</span><br><span class="line">extern float fabsf(float);</span><br><span class="line">extern double fabs(double);</span><br><span class="line">extern long double fabsl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算参数的实立方根</span><br><span class="line">extern float cbrtf(float);</span><br><span class="line">extern double cbrt(double);</span><br><span class="line">extern long double cbrtl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求值直角三角形的斜边长度，给出的两边为 x 和 y (换言之，根的长度 x2 + y2)。</span><br><span class="line">extern float hypotf(float, float);</span><br><span class="line">extern double hypot(double, double);</span><br><span class="line">extern long double hypotl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求n的m次方的值,计算以n为底数的m次幂</span><br><span class="line">extern float powf(float, float);</span><br><span class="line">extern double pow(double, double);</span><br><span class="line">extern long double powl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 开平方</span><br><span class="line">extern float sqrtf(float);</span><br><span class="line">extern double sqrt(double);</span><br><span class="line">extern long double sqrtl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 函数返回 x 的高斯误差函数</span><br><span class="line">extern float erff(float);</span><br><span class="line">extern double erf(double);</span><br><span class="line">extern long double erfl(long double);</span><br><span class="line">//https://msdn.microsoft.com/zh-cn/library/</span><br><span class="line">//TODO: 函数返回 x 的补余高斯误差函数。</span><br><span class="line">extern float erfcf(float);</span><br><span class="line">extern double erfc(double);</span><br><span class="line">extern long double erfcl(long double);</span><br></pre></td></tr></table></figure>


<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">/* ===================</span><br><span class="line"> lgammaf, lgamma, and lgammal are not thread-safe. The thread-safe</span><br><span class="line"> variants lgammaf_r, lgamma_r, and lgammal_r are made available if</span><br><span class="line"> you define the _REENTRANT symbol before including &lt;math.h&gt;           </span><br><span class="line"> ====================== */</span><br><span class="line">#pragma mark ---lgammaf...</span><br><span class="line">//TODO: 计算伽玛参数绝对值的自然对数</span><br><span class="line">extern float lgammaf(float);</span><br><span class="line">extern double lgamma(double);</span><br><span class="line">extern long double lgammal(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算_X 的伽玛函数</span><br><span class="line">extern float tgammaf(float);</span><br><span class="line">extern double tgamma(double);</span><br><span class="line">extern long double tgammal(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算值的上限。向上取整 进1</span><br><span class="line">extern float ceilf(float);</span><br><span class="line">extern double ceil(double);</span><br><span class="line">extern long double ceill(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 对参数向下取整，返回参数的下限。</span><br><span class="line">extern float floorf(float);</span><br><span class="line">extern double floor(double);</span><br><span class="line">extern long double floorl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 通过使用当前舍入方向，舍入参数为浮点格式的一个整数值，整数。返回舍入的整数值。</span><br><span class="line">extern float nearbyintf(float);</span><br><span class="line">extern double nearbyint(double);</span><br><span class="line">extern long double nearbyintl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 将浮点值舍入到最接近的整数（采用浮点格式），四舍五入函数</span><br><span class="line">extern float rintf(float);</span><br><span class="line">extern double rint(double);</span><br><span class="line">extern long double rintl(long double);</span><br><span class="line"></span><br><span class="line">//FIXME: 也是四舍五入</span><br><span class="line">extern long int lrintf(float);</span><br><span class="line">extern long int lrint(double);</span><br><span class="line">extern long int lrintl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 四舍五入法</span><br><span class="line">extern float roundf(float);</span><br><span class="line">extern double round(double);</span><br><span class="line">extern long double roundl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 四舍五入，取最接近的整数</span><br><span class="line">extern long int lroundf(float);</span><br><span class="line">extern long int lround(double);</span><br><span class="line">extern long int lroundl(long double);</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">#pragma mark ---truncf...</span><br><span class="line">/* ======================</span><br><span class="line"> long long is not part of C90. Make sure you are passing -std=c99 or</span><br><span class="line"> -std=gnu99 or higher if you need these functions returning long longs     </span><br><span class="line">   ====================== */</span><br><span class="line">//TODO: 截断参数为整数部分，返回参数的整数部分</span><br><span class="line">extern float truncf(float);</span><br><span class="line">extern double trunc(double);</span><br><span class="line">extern long double truncl(long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求两数整除后的余数</span><br><span class="line">extern float fmodf(float, float);</span><br><span class="line">extern double fmod(double, double);</span><br><span class="line">extern long double fmodl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算余数 _X 除 _Y</span><br><span class="line">extern float remainderf(float, float);</span><br><span class="line">extern double remainder(double, double);</span><br><span class="line">extern long double remainderl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算第一个指定参数除以第二个指定参数的余数。也要计算出第一指定参数的有效位数除以第二指定参数的有效位数的商，然后使用在第三参数中指定的位置返回该商。</span><br><span class="line">extern float remquof(float, float, int *);</span><br><span class="line">extern double remquo(double, double, int *);</span><br><span class="line">extern long double remquol(long double, long double, int *);</span><br><span class="line"></span><br><span class="line">//TODO: 用_X的大小和_Y的符号来返回值</span><br><span class="line">extern float copysignf(float, float);</span><br><span class="line">extern double copysign(double, double);</span><br><span class="line">extern long double copysignl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 用_X中指示的内容返回清扫NaN，</span><br><span class="line">extern float nanf(const char *);</span><br><span class="line">extern double nan(const char *);</span><br><span class="line">extern long double nanl(const char *);</span><br><span class="line"></span><br><span class="line">extern float nextafterf(float, float);</span><br><span class="line">extern double nextafter(double, double);</span><br><span class="line">extern long double nextafterl(long double, long double);</span><br><span class="line"></span><br><span class="line">extern double nexttoward(double, long double);</span><br><span class="line">extern float nexttowardf(float, long double);</span><br><span class="line">extern long double nexttowardl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算参数之间的正整数差异。（如果 _X 比 _Y 大，_X 和 _Y 之间的差异；否则，+0。）</span><br><span class="line">extern float fdimf(float, float);</span><br><span class="line">extern double fdim(double, double);</span><br><span class="line">extern long double fdiml(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求最大值</span><br><span class="line">extern float fmaxf(float, float);</span><br><span class="line">extern double fmax(double, double);</span><br><span class="line">extern long double fmaxl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 求最小值</span><br><span class="line">extern float fminf(float, float);</span><br><span class="line">extern double fmin(double, double);</span><br><span class="line">extern long double fminl(long double, long double);</span><br><span class="line"></span><br><span class="line">//TODO: 计算第一个和第二个指定的参数的产品，然后将第三个指定的参数添加到结果；整个计算是作为单个操作执行的。表达式 (_X x _Y) + _Z 的结果。整个计算都作为单个操作执行，即子表达式计算到无限精度并且仅对最终结果四舍五入。</span><br><span class="line">extern float fmaf(float, float, float);</span><br><span class="line">extern double fma(double, double, double);</span><br><span class="line">extern long double fmal(long double, long double, long double);</span><br></pre></td></tr></table></figure>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">kyren</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huluo666.gitee.io/2016/04/16/iOS开发之C语言函数库/">http://huluo666.gitee.io/2016/04/16/iOS开发之C语言函数库/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huluo666.gitee.io">Kyren's Blog</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/iOS/">iOS</a></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2016/04/16/iOS%20%E6%88%AA%E5%9B%BE/"><i class="fa fa-chevron-left">  </i><span>iOS截图</span></a></div><div class="next-post pull-right"><a href="/2016/04/15/iOS%20%E4%B8%AD%E7%9A%84%E7%B3%BB%E7%BB%9F%E5%B8%B8%E7%94%A8%E5%AE%8F%E5%AE%9A%E4%B9%89/"><span>iOS 中的系统常用宏定义NSObjCRuntime.h</span><i class="fa fa-chevron-right"></i></a></div></nav></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2022 By kyren</div><div class="framework-info"><span>驱动 - </span><a target="_blank" rel="noopener" href="http://hexo.io"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a target="_blank" rel="noopener" href="https://github.com/Molunerfinn/hexo-theme-melody"><span>Melody</span></a></div><div class="footer_custom_text">hitokoto</div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv"><i class="fa fa-file"></i><span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/lib/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.9.0"></script><script src="/js/fancybox.js?version=1.9.0"></script><script src="/js/sidebar.js?version=1.9.0"></script><script src="/js/copy.js?version=1.9.0"></script><script src="/js/fireworks.js?version=1.9.0"></script><script src="/js/transition.js?version=1.9.0"></script><script src="/js/scroll.js?version=1.9.0"></script><script src="/js/head.js?version=1.9.0"></script><script src="/js/search/local-search.js"></script><script>if(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
  $('#top-container').addClass('is-mobile')
}</script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html>